package com.tigger.common.utils;

import java.security.Key;

import javax.crypto.spec.SecretKeySpec;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class EsJwt {

    private final static byte[] KEY_SECRET = "1234567890123456".getBytes();

    public static Claims parseJWT(String jwt) throws Exception {
        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
        Key secretKey = generalKey(signatureAlgorithm);
        return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(jwt).getBody();
    }

    public static Key generalKey(SignatureAlgorithm signatureAlgorithm) {
        Key signKey = new SecretKeySpec(KEY_SECRET, signatureAlgorithm.getJcaName());
        return signKey;
    }
}
